/**
 * SWFAddress 2.2:Deep linking for Flash and Ajax <http://www.asual.com/swfaddress/>
 *
 * SWFAddress is (c) 2006-2008 Rostislav Hristov and contributors
 * This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
 *
 */
package com.asual.swfaddress;

#if flash8
class SWFAddressEvent {
#elseif flash9
class SWFAddressEvent extends flash.events.Event {
#end
	inline public static var INIT :String = 'init';
	inline public static var CHANGE :String = 'change';
	
	//public var type (get, null) :String;
	public var value (get, null) :String;
	public var path (get, null) :String;
	public var pathNames (get, null) :Array<String>;
	public var parameters (get, null) :Array<String>;
	public var parametersNames (get, null) :Array<String>;
	
	public function new (type:String) {
		#if flash9 super(type);#end
		//this.type = type;
	}
	
	#if flash9 override#end public function toString():String {
        return '[class SWFAddressEvent]';
    }
	
	public function getTarget () :Dynamic {
		return SWFAddress;
	}
	
	function get_value () :String {
		if (value == 'undefined' || value == null)
            value = SWFAddress.getValue();
		return value;
	}
	
	function get_path () :String {
		if (path == 'undefined' || path == null)
            path = SWFAddress.getPath();
		return path;
	}
	
	function get_pathNames () :Array<String> {
		if (/*pathNames == 'undefined' || */pathNames == null)
            pathNames = SWFAddress.getPathNames();
		return pathNames;
	}
	
	function get_parameters () :Array<String> {
		if (/*parameters == 'undefined' || */parameters == null) {
			parameters = new Array<String>();
			var params:Array<String> = parametersNames;
			
			for (i in 0...params.length)
				Reflect.setField (parameters, params[i], SWFAddress.getParameter (params[i]));
		}
		return parameters;
	}
	
	function get_parametersNames () :Array<String> {
		if (/*parametersNames == 'undefined' || */parametersNames == null)
			parametersNames = SWFAddress.getParameterNames();
		return parametersNames;
	}
}
